package com.ibm.iocc67;

import java.io.IOException;
import javax.portlet.*;
import javax.faces.context.FacesContext;


public class Iocc67tiepnhanmapPortlet extends com.ibm.faces.portlet.FacesPortlet {
	
	public static final String IS_MOBILE = "ismobile";
	
	
	public static final String TRUE = "true";
	public static final String FALSE = "false";
	
		
	public static final String IS_TABLET = "istablet";
	

	
	public static final String USER_AGENT	= "User-Agent";
	
	
	public static final String WINDOWSPHONE	= "windowsphone";
	
	public static final String ANDROID	= "android";
	
	public static final String BLACKBERRY	= "blackberry";
	
	public static final String IPHONE	= "iphone";
	
	
	
	public static final String IPAD = "ipad";
	
	public void destroy() {
		super.destroy();
	}
	
	public void doConfigure(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		super.doConfigure(request, response);
	}
	
	
	public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		super.doEdit(request, response);
	}
	
	public void doHelp(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		super.doHelp(request, response);
	}
	
	public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
		
		
		String userAgent = request.getProperty(USER_AGENT).toLowerCase();
			
			if(userAgent.contains(IPAD)) {
				request.setAttribute(IS_TABLET, TRUE);
			}
			
		
		 else if(userAgent.contains(WINDOWSPHONE)||userAgent.contains(ANDROID)||userAgent.contains(BLACKBERRY)||userAgent.contains(IPHONE)){
			request.setAttribute(IS_MOBILE, TRUE);
		}
		
		else{
		
			request.setAttribute(IS_MOBILE, FALSE);
		
		
			request.setAttribute(IS_TABLET, FALSE);
		
		}
		
		super.doView(request, response);
	}
	
	public void init() throws PortletException {
		super.init();
	}
	
		
	
	
	public void processAction(ActionRequest request, ActionResponse response) throws PortletException {
		
		super.processAction(request, response);
	}
		
	
	
	
	
	public String getView(FacesContext fContext, String mode){
		
		String isTablet = null;
		
		
		String isMobile = null;
		
	    
		String jspName=null; 
		 
		PortletRequest request =  (PortletRequest)fContext.getExternalContext().getRequest();
		
			if(request.getAttribute(IS_TABLET)!=null)
				isTablet = request.getAttribute(IS_TABLET).toString();
		
		
			if(request.getAttribute(IS_MOBILE)!=null)
				isMobile = request.getAttribute(IS_MOBILE).toString();
			
		
		
		
		 if((isTablet)!=null && isTablet.equals(TRUE)){   
						
			if(mode.equals("view"))
				jspName="/iocc67tiepnhanmapView_Tablets.jsp";
			
		}
		
		
		 else if((isMobile)!=null && isMobile.equals(TRUE)){   
					
			if(mode.equals("view"))
				jspName="/iocc67tiepnhanmapView_Devices.jsp";
			
		}
		
		else{
			if(mode.equals("view"))
				jspName="/iocc67tiepnhanmapView.jsp";
			
		}
		return jspName;
		
		
		
		
	}
}